package com.example.mvvmcore.view;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;

import com.example.mvvmcore.viewmodel.BaseViewModel;
import com.example.mvvmcore.viewmodel.MyViewModelFactory;

public abstract class BaseMVVMActivity<VM extends BaseViewModel> extends BaseActivity{
    protected VM mViewModel=null;

    @Override
    protected void initEnv() {
        super.initEnv();
//        mViewModel=createViewModel();
        MyViewModelFactory factory=new MyViewModelFactory(this);
        mViewModel = (VM) new ViewModelProvider(this,factory).get(getViewModelClazz());
    }

    protected abstract Class getViewModelClazz();

    /**
     * 创建ViewModel实例
     * @return
     */
//    protected abstract VM createViewModel();
}
